function residual = dynamic_resid(T, y, x, params, steady_state, it_, T_flag)
% function residual = dynamic_resid(T, y, x, params, steady_state, it_, T_flag)
%
% File created by Dynare Preprocessor from .mod file
%
% Inputs:
%   T             [#temp variables by 1]     double   vector of temporary terms to be filled by function
%   y             [#dynamic variables by 1]  double   vector of endogenous variables in the order stored
%                                                     in M_.lead_lag_incidence; see the Manual
%   x             [nperiods by M_.exo_nbr]   double   matrix of exogenous variables (in declaration order)
%                                                     for all simulation periods
%   steady_state  [M_.endo_nbr by 1]         double   vector of steady state values
%   params        [M_.param_nbr by 1]        double   vector of parameter values in declaration order
%   it_           scalar                     double   time period for exogenous variables for which
%                                                     to evaluate the model
%   T_flag        boolean                    boolean  flag saying whether or not to calculate temporary terms
%
% Output:
%   residual
%

if T_flag
    T = model_5_IRFs.dynamic_resid_tt(T, y, x, params, steady_state, it_);
end
residual = zeros(46, 1);
lhs = y(40);
rhs = T(1);
residual(1) = lhs - rhs;
lhs = y(42);
rhs = T(2);
residual(2) = lhs - rhs;
lhs = y(41);
rhs = T(3);
residual(3) = lhs - rhs;
lhs = y(43);
rhs = T(18);
residual(4) = lhs - rhs;
lhs = 1/y(37);
rhs = T(4)*T(5)+params(1)*(1-params(8))/y(54);
residual(5) = lhs - rhs;
residual(6) = y(33);
lhs = y(37);
rhs = params(3)*T(6)^((params(3)-1)/params(3));
residual(7) = lhs - rhs;
lhs = y(23)^(-params(2));
rhs = params(6)/(1-params(5))/y(37);
residual(8) = lhs - rhs;
lhs = y(37)*y(45)/params(6);
rhs = y(1)*T(19);
residual(9) = lhs - rhs;
lhs = y(14);
rhs = 0.5*(1+erf(T(7)));
residual(10) = lhs - rhs;
lhs = y(26);
rhs = T(8);
residual(11) = lhs - rhs;
lhs = y(27);
rhs = y(49);
residual(12) = lhs - rhs;
lhs = y(38);
rhs = 1/params(1)-1;
residual(13) = lhs - rhs;
lhs = y(39);
rhs = (1+y(38))*(1+y(27))-1;
residual(14) = lhs - rhs;
lhs = y(21)*y(44)*(1-params(4));
rhs = params(12)*(1-params(8))-(1-params(8))*(1-y(2));
residual(15) = lhs - rhs;
lhs = y(36);
rhs = y(1)*params(10)*y(14)*T(20);
residual(16) = lhs - rhs;
lhs = y(35);
rhs = y(1)*params(10)*y(14)*T(9);
residual(17) = lhs - rhs;
lhs = y(28)*(y(36)+y(35)+y(24));
rhs = y(36)+y(35);
residual(18) = lhs - rhs;
lhs = (y(36)+y(35))*y(29);
rhs = y(36);
residual(19) = lhs - rhs;
lhs = y(22);
rhs = y(1)*params(52)+y(40)*y(1)*params(10)*y(14)+y(43)*y(1)*params(10)*y(14);
residual(20) = lhs - rhs;
lhs = y(25);
rhs = y(23)+y(50)+y(32)-y(1)*(1-params(8));
residual(21) = lhs - rhs;
lhs = y(25);
rhs = y(21)*y(22)/(1-params(3));
residual(22) = lhs - rhs;
lhs = y(24);
rhs = y(32)-y(1)*(1-params(8));
residual(23) = lhs - rhs;
lhs = y(34);
rhs = y(22)*T(11);
residual(24) = lhs - rhs;
lhs = T(13)*T(14)*T(15);
rhs = y(25);
residual(25) = lhs - rhs;
lhs = y(31);
rhs = T(13);
residual(26) = lhs - rhs;
lhs = y(46);
rhs = T(16);
residual(27) = lhs - rhs;
lhs = y(47);
rhs = T(17);
residual(28) = lhs - rhs;
lhs = y(17);
rhs = log(y(37))-log((steady_state(32)));
residual(29) = lhs - rhs;
lhs = y(13);
rhs = log(1+y(27))-log(1+(steady_state(22)));
residual(30) = lhs - rhs;
lhs = y(19);
rhs = y(39)-(steady_state(34));
residual(31) = lhs - rhs;
lhs = y(11);
rhs = log(y(28))-log((steady_state(23)));
residual(32) = lhs - rhs;
lhs = y(12);
rhs = log(y(29))-log((steady_state(24)));
residual(33) = lhs - rhs;
lhs = y(20);
rhs = log(y(30))-log((steady_state(25)));
residual(34) = lhs - rhs;
lhs = y(10);
rhs = log(y(31))-log((steady_state(26)));
residual(35) = lhs - rhs;
residual(36) = y(18);
lhs = y(6);
rhs = log(y(25)+y(37)*y(26)*params(15)-y(50))-log((steady_state(20)+steady_state(32)*steady_state(21)*params(15)-steady_state(45)));
residual(37) = lhs - rhs;
lhs = y(8);
rhs = log(y(24))-log((steady_state(19)));
residual(38) = lhs - rhs;
lhs = y(7);
rhs = log(y(23)+y(37)*y(26)*params(15))-log((steady_state(18)+steady_state(32)*steady_state(21)*params(15)));
residual(39) = lhs - rhs;
lhs = y(9);
rhs = log(y(26)+y(34))-log((steady_state(21)+steady_state(29)));
residual(40) = lhs - rhs;
lhs = y(16);
rhs = log(y(46))-log((steady_state(41)));
residual(41) = lhs - rhs;
lhs = y(15);
rhs = log(y(47))-log((steady_state(42)));
residual(42) = lhs - rhs;
lhs = log(y(48))-log(params(11));
rhs = params(22)*(log(y(2))-log(params(11)))+params(26)*x(it_, 1);
residual(43) = lhs - rhs;
lhs = log(1+y(49))-log(1+params(7));
rhs = params(24)*(log(1+y(3))-log(1+params(7)))-params(28)*x(it_, 3);
residual(44) = lhs - rhs;
lhs = log(y(51))-log(params(35));
rhs = params(23)*(log(y(5))-log(params(35)))+params(27)*x(it_, 2);
residual(45) = lhs - rhs;
lhs = log(y(50))-log(params(34));
rhs = params(25)*(log(y(4))-log(params(34)))+params(29)*x(it_, 4);
residual(46) = lhs - rhs;

end
